<template>
  <div class="training-deploy-container">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-left">
        <h1 class="page-title">模型训练与部署</h1>
        <p class="page-subtitle">配置、训练和部署机器学习模型</p>
      </div>
      <div class="header-right">
        <button class="header-btn" @click="loadTemplate">
          加载模板
        </button>
        <button class="header-btn primary" @click="createNewModel">
          新建模型
        </button>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="main-content">
      <!-- 左侧配置面板 -->
      <div class="config-panel">
        <!-- 基本信息 -->
        <div class="config-section">
          <h3 class="section-title">基本信息</h3>
          <div class="form-group">
            <label class="form-label">模型名称</label>
            <input
                v-model="modelConfig.name"
                type="text"
                class="form-input"
                placeholder="输入模型名称"
            />
          </div>
          <div class="form-group">
            <label class="form-label">模型类型</label>
            <select v-model="modelConfig.type" class="form-select">
              <option value="">选择模型类型</option>
              <option value="prediction">预测模型</option>
              <option value="diagnosis">诊断模型</option>
              <option value="classification">分类模型</option>
            </select>
          </div>
        </div>

        <!-- 操作按钮 -->
        <div class="action-buttons">
          <button class="action-btn save" @click="saveConfig">
            保存配置
          </button>
          <button
              class="action-btn train"
              @click="startTraining"
              :disabled="!isConfigValid"
          >
            开始训练
          </button>
          <button
              class="action-btn deploy"
              @click="deployModel"
              :disabled="!isTrainingComplete"
          >
            部署模型
          </button>
        </div>
      </div>

      <!-- 右侧监控面板 -->
      <div class="monitor-panel">
        <div class="monitor-section">
          <h3 class="section-title">训练监控</h3>
          <div v-if="!isTraining" class="empty-state">
            <div class="empty-icon">🚀</div>
            <p>配置完成后点击"开始训练"</p>
          </div>

          <div v-else class="training-status">
            <div class="status-info">
              <span class="status-label">状态:</span>
              <span class="status-value">{{ trainingStatus }}</span>
            </div>

            <div class="progress-bars">
              <div class="progress-item">
                <label class="progress-label">整体进度: {{ overallProgress }}%</label>
                <div class="progress-bar">
                  <div
                      class="progress-fill"
                      :style="{ width: overallProgress + '%' }"
                  ></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import {ref, computed, onMounted, reactive} from 'vue'

// 响应式数据
const modelConfig = reactive({
  name: '',
  type: '',
  description: '',
  version: '1.0.0'
})

const isTraining = ref(false)
const trainingStatus = ref('待开始')
const overallProgress = ref(0)
const isTrainingComplete = ref(false)

// 计算属性
const isConfigValid = computed(() => {
  return modelConfig.name && modelConfig.type
})

// 方法
const loadTemplate = () => {
  console.log('加载模板')
}

const createNewModel = () => {
  console.log('创建新模型')
  Object.assign(modelConfig, {
    name: '',
    type: '',
    description: '',
    version: '1.0.0'
  })
}

const saveConfig = () => {
  console.log('保存配置:', modelConfig)
}

const startTraining = async () => {
  if (!isConfigValid.value) {
    return
  }

  isTraining.value = true
  trainingStatus.value = '训练中'

  // 模拟训练进度
  for (let i = 0; i <= 100; i += 10) {
    overallProgress.value = i
    await new Promise(resolve => setTimeout(resolve, 200))
  }

  isTraining.value = false
  trainingStatus.value = '训练完成'
  isTrainingComplete.value = true
}

const deployModel = () => {
  console.log('部署模型')
}

onMounted(() => {
  console.log('模型训练与部署页面已加载')
})
</script>

<style scoped>
.training-deploy-container {
  width: 92vw;
  min-height: 100vh;
  padding: 2vw;
  background: #0c1120;
  color: #e6e6e6;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3vh;
  padding: 2vh 2vw;
  background: #121a2d;
  border-radius: 12px;
  border: 1px solid #2d3a4b;
}

.page-title {
  font-size: 3.5vw;
  margin: 0 0 0.5vh 0;
  font-weight: 700;
}

.page-subtitle {
  font-size: 1.6vw;
  margin: 0;
  opacity: 0.9;
}

.header-right {
  display: flex;
  gap: 1vw;
}

.header-btn {
  background: #121a2d;
  border: 1px solid #2d3a4b;
  color: #e6e6e6;
  padding: 1vh 2vw;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.2vw;
  font-weight: 500;
  transition: all 0.3s ease;
}

.header-btn:hover {
  background: #263445;
  transform: translateY(-2px);
}

.header-btn.primary {
  background: linear-gradient(45deg, #409EFF, #337ecc);
  border-color: #409EFF;
}

.main-content {
  display: flex;
  gap: 2vw;
  height: calc(100vh - 12vh);
}

.config-panel {
  width: 40vw;
  background: #121a2d;
  border-radius: 15px;
  padding: 2vh 1.5vw;
  border: 1px solid #2d3a4b;
  overflow-y: auto;
  max-height: 100%;
}

.monitor-panel {
  flex: 1;
  background: #121a2d;
  border-radius: 15px;
  padding: 2vh 1.5vw;
  border: 1px solid #2d3a4b;
  overflow-y: auto;
  max-height: 100%;
}

.config-section, .monitor-section {
  margin-bottom: 3vh;
}

.section-title {
  font-size: 1.6vw;
  margin-bottom: 1.5vh;
  color: #409EFF;
  border-bottom: 1px solid #2d3a4b;
  padding-bottom: 0.5vh;
}

.form-group {
  margin-bottom: 2vh;
}

.form-label {
  display: block;
  font-size: 1.2vw;
  margin-bottom: 0.8vh;
  color: #e6e6e6;
}

.form-input, .form-select {
  width: 100%;
  background: #0e1525;
  border: 1px solid #2d3a4b;
  border-radius: 8px;
  color: #e6e6e6;
  padding: 1vh 1.2vw;
  font-size: 1.1vw;
  outline: none;
  transition: border-color 0.3s ease;
  box-sizing: border-box;
}

.form-input:focus, .form-select:focus {
  border-color: #409EFF;
}

.form-select option {
  background: #121a2d;
  color: #e6e6e6;
}

.action-buttons {
  display: flex;
  gap: 1vw;
  margin-top: 2vh;
  padding-top: 2vh;
  border-top: 1px solid #2d3a4b;
}

.action-btn {
  flex: 1;
  background: #121a2d;
  border: 1px solid #2d3a4b;
  color: #e6e6e6;
  padding: 1.5vh 1vw;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.2vw;
  font-weight: 600;
  transition: all 0.3s ease;
}

.action-btn:hover:not(:disabled) {
  background: #263445;
  transform: translateY(-2px);
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.action-btn.save {
  background: linear-gradient(45deg, #2196F3, #1976D2);
  border-color: #2196F3;
}

.action-btn.train {
  background: linear-gradient(45deg, #409EFF, #337ecc);
  border-color: #409EFF;
}

.action-btn.deploy {
  background: linear-gradient(45deg, #FF9800, #F57C00);
  border-color: #FF9800;
}

.empty-state {
  text-align: center;
  padding: 4vh 0;
  opacity: 0.7;
}

.empty-icon {
  font-size: 4vw;
  margin-bottom: 1vh;
}

.training-status {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  padding: 2vh 1.5vw;
}

.status-info {
  margin-bottom: 2vh;
}

.status-label {
  opacity: 0.8;
  margin-right: 1vw;
}

.status-value {
  font-weight: 600;
  color: #409EFF;
}

.progress-bars {
  margin-bottom: 2vh;
}

.progress-item {
  margin-bottom: 1.5vh;
}

.progress-label {
  display: block;
  font-size: 1.1vw;
  margin-bottom: 0.5vh;
  opacity: 0.9;
}

.progress-bar {
  position: relative;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  height: 20px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #409EFF, #66b1ff);
  transition: width 0.3s ease;
  border-radius: 10px;
}
</style>